package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Random;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CanteenMapper;
import com.ruoyi.system.domain.Canteen;
import com.ruoyi.system.service.ICanteenService;

/**
 * 食堂信息Service业务层处理
 * 
 * @author Wxl
 * @date 2022-03-13
 */
@Service
public class CanteenServiceImpl implements ICanteenService 
{
    @Autowired
    private CanteenMapper canteenMapper;
    @Autowired
    private SysDictDataMapper dictMapper;
    /**
     * 查询食堂信息
     * 
     * @param id 食堂信息主键
     * @return 食堂信息
     */
    @Override
    public Canteen selectCanteenById(Long id)
    {
        return canteenMapper.selectCanteenById(id);
    }

    /**
     * 查询食堂信息列表
     * 
     * @param canteen 食堂信息
     * @return 食堂信息
     */
    @Override
    public List<Canteen> selectCanteenList(Canteen canteen)
    {
        return canteenMapper.selectCanteenList(canteen);
    }

    /**
     * 新增食堂信息
     * 
     * @param canteen 食堂信息
     * @return 结果
     */
    @Override
    public int insertCanteen(Canteen canteen)
    {
        long id = new Date().getTime();
        canteen.setId(id);
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictLabel(canteen.getName());
        sysDictData.setDictValue(String.valueOf(id));
        sysDictData.setDictSort(999L);
        sysDictData.setDictType("canteen_id");
        sysDictData.setCssClass("1");
        sysDictData.setListClass("primary");
        sysDictData.setStatus("0");
        sysDictData.setIsDefault("N");
        sysDictData.setCreateBy("admin");
        dictMapper.insertDictData(sysDictData);
        return canteenMapper.insertCanteen(canteen);
    }

    /**
     * 修改食堂信息
     * 
     * @param canteen 食堂信息
     * @return 结果
     */
    @Override
    public int updateCanteen(Canteen canteen)
    {
        return canteenMapper.updateCanteen(canteen);
    }

    /**
     * 批量删除食堂信息
     * 
     * @param ids 需要删除的食堂信息主键
     * @return 结果
     */
    @Override
    public int deleteCanteenByIds(Long[] ids)
    {
        return canteenMapper.deleteCanteenByIds(ids);
    }

    /**
     * 删除食堂信息信息
     * 
     * @param id 食堂信息主键
     * @return 结果
     */
    @Override
    public int deleteCanteenById(Long id)
    {
        return canteenMapper.deleteCanteenById(id);
    }
}
